package com.hopu.blb_erp.controller;

import com.hopu.blb_erp.entity.Organization;
import com.hopu.blb_erp.entity.PageEntity;
import com.hopu.blb_erp.entity.Site;
import com.hopu.blb_erp.entity.User;
import com.hopu.blb_erp.service.OrganizationService;
import com.hopu.blb_erp.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api
@RestController
public class OrganizationController {

    @Autowired
    private OrganizationService organizationService;

    @ApiOperation("分页查询机构")
    @GetMapping("/organs/{current}/{pageSize}")
    public ResponseEntity<PageEntity> findPage(@PathVariable("current")Integer current, @PathVariable("pageSize")Integer pageSize){
        PageEntity<Organization> page = organizationService.findPage(current, pageSize);
        return ResponseEntity.ok(page);
    }

    @ApiOperation("添加机构")
    @PostMapping("/organ")
    public ResponseEntity<String> add(@RequestBody Organization organization){
        organizationService.save(organization);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation("删除机构")
    @DeleteMapping("/organ/{id}")
    public ResponseEntity<String> delete(@PathVariable("id") Long id){
        organizationService.removeById(id);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation("更新机构")
    @PutMapping("/organ")
    public ResponseEntity<String> modify(@RequestBody Organization organization){
        organizationService.updateById(organization);
        return ResponseEntity.ok("ok");
    }
}
